package com.hy.example.shared.events;



import com.hy.example.shared.utils.SpringUtil;
import com.hy.example.shared.utils.UserAuditorHelper;
import lombok.*;
import org.springframework.cloud.bus.BusProperties;
import org.springframework.cloud.bus.event.Destination;
import org.springframework.cloud.bus.event.RemoteApplicationEvent;

import java.util.UUID;

@Getter
@Setter
@ToString(of = {"id", "token", "at" })
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public abstract class AbstractBusEvent extends RemoteApplicationEvent {
    private static final Destination DEFAULT_DEST = () -> "**";
    private String id;
    private String token;
    private long at;

    protected AbstractBusEvent(Object source) {
        super(source, SpringUtil.getBean(BusProperties.class).getId(), DEFAULT_DEST);
        this.id = UUID.randomUUID().toString();
        this.token = UserAuditorHelper.retrieveCurrentToken().orElse(null);
        this.at = System.currentTimeMillis();
    }
}
